<?php

// Copyright 2005, Google Inc. All rights reserved.

/**
 *  sample code to create an Adsense account through Adsense API
 */

require_once('lib/nusoap.php');
require_once('common.php');

$server = 'https://sandbox.google.com';
// Comment out the line above and uncomment the line below to use
// the production API server
// $server = 'https://www.google.com';
$namespace = 'http://www.google.com/api/adsense/v3';

// Set up the authentication headers
$email = "<developer_email>REPLACE WITH DEVELOPER EMAIL</developer_email>";
$password = "<developer_password>REPLACE WITH DEVELOPER PASSWORD</developer_password>";
$client_id = "<client_id>NOT RELEVANT</client_id>";

$header = $email . $password . $client_id;

// creating soap client
$wsdl = $server . '/api/adsense/v3/AccountService?wsdl';
$client = new soapclient($wsdl, true);
$err = $client->getError();
if ($err) {
  showSoapClientError($err);
  return;
}
$client->soap_defencoding = 'UTF-8';

// Set the headers; they are needed for authentication
$client->setHeaders($header);
if ($client->fault) {
  showMyErrors($client);
  return;
}
$err = $client->getError();
if ($err) {
  showSoapClientError($err);
  return;
}

// setting the parameter
$param = "<loginEmail>users_address_here@example.com</loginEmail>";
$param .= "<postalCode>USERS POSTAL CODE</postalCode>";
$param .= "<phone>USERS PHONE NUMBER</phone>";
$param .= "<developerUrl>SITE TO BE ASSOCIATED WITH THIS PUBLISHER</developerUrl>";
$param = "<ns1:associateAccount xmlns:ns1=\"$namespace\">" . $param . "</ns1:associateAccount>";

// invoke web service
showCall('associateAccount', $param);
$response = $client->call('associateAccount', $param, $namespace);
if ($client->fault) {
  showMyErrors($client);
  return;
}
$err = $client->getError();
if ($err) {
  showSoapClientError($err);
  return;
}

// get back the response
$response = $response['return'];
showCreatedPublisher($response);

// showing the soap
showRequestResponse($client);

?>
